<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller{
    public function login(){
        $this->display();
    }
    public function dologin(){
        $AdminUser=D('adminuser');
        $data=$AdminUser->userlogin($_POST['name'],$_POST['pass']);          
        if($data){
            $output=array();
            $output['status']=1;
            $output['info']="登录成功";
            $output['url']=U('./admin/content/lists');
            print json_encode($output);
            exit;
        }else{
            $output=array();
            $output['status']=0;
            $output['info']="*账号或密码不正确";
            $output['url']=U('login');
            print json_encode($output);
            exit;
        }        
    }
    public function register(){            
            $this->display();          
        }
    public function Verification(){
            $model=D('adminuser');
            $data=$model->userfind($_POST['name']); 
            if($data){
            $output=array();
            $output['status']=0;
            $output['info']="*用户名已存在";
            print json_encode($output);
            exit;
        }else if(empty($_POST['name'])){
            $output=array();
            $output['status']=2;
            $output['info']="*用户名不能为空";
            $output['url']=U('register');
            print json_encode($output);
            exit;                    
        }else{           
            $output=array();
            $output['status']=1;
            $output['info']="";
            $output['url']=U('login');
            print json_encode($output);
            exit;
        }
    }
    public function doregister(){
        $model=D('adminuser');
        $model->register($_POST['name'],$_POST['pass']);
        $output=array();
        $output['status']=1;
        $output['info']="";
        $output['url']=U('login');
        print json_encode($output);
        exit;
    }
    public function lists(){
        $model=D('user');
        $data=$model->userlists();
        $this->assign('data',$data);
        $this->display();
    }
    public function delete(){
        $newmodel=M('user');
        $map=array();
        $map['id']=$_GET['id'];
        $newmodel->where('id='.$map['id'])->delete();
        $this->redirect('./Admin/user/lists');
    }
}
